/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
 * Description: UDK operations source file
 * Author: -
 * Create: 2021.4.19
 */
#include <errno.h>
#include "udk_ops.h"

struct udk_callback_ops g_udk_reg_ops = { 0 };

int32_t udk_register_ops(struct udk_callback_ops *reg_ops)
{
    if (reg_ops == NULL) {
        return -EINVAL;
    }

    /* register malloc/free ops */
    g_udk_reg_ops.free = reg_ops->free;
    g_udk_reg_ops.malloc_socket = reg_ops->malloc_socket;

    /* register ring ops */
    g_udk_reg_ops.ring_create = reg_ops->ring_create;
    g_udk_reg_ops.ring_lookup = reg_ops->ring_lookup;
    g_udk_reg_ops.ring_free = reg_ops->ring_free;
    g_udk_reg_ops.ring_dequeue = reg_ops->ring_dequeue;
    g_udk_reg_ops.ring_enqueue = reg_ops->ring_enqueue;
    g_udk_reg_ops.ring_full = reg_ops->ring_full;
    g_udk_reg_ops.ring_dump = reg_ops->ring_dump;
    g_udk_reg_ops.ring_count = reg_ops->ring_count;
    g_udk_reg_ops.ring_free_count = reg_ops->ring_free_count;

    /* register mempzone ops */
    g_udk_reg_ops.memzone_lookup = reg_ops->memzone_lookup;
    g_udk_reg_ops.memzone_reserve = reg_ops->memzone_reserve;
    g_udk_reg_ops.memzone_free = reg_ops->memzone_free;
    g_udk_reg_ops.memzone_reserve_aligned = reg_ops->memzone_reserve_aligned;

    /* register mempool ops */
    g_udk_reg_ops.mempool_create = reg_ops->mempool_create;
    g_udk_reg_ops.mempool_free = reg_ops->mempool_free;
    g_udk_reg_ops.mempool_put = reg_ops->mempool_put;
    g_udk_reg_ops.mempool_get_bulk = reg_ops->mempool_get_bulk;
    g_udk_reg_ops.mempool_avail_count = reg_ops->mempool_avail_count;
    g_udk_reg_ops.mempool_in_use_count = reg_ops->mempool_in_use_count;
    g_udk_reg_ops.mempool_lookup = reg_ops->mempool_lookup;

    /* register mbuf ops */
    g_udk_reg_ops.pktmbuf_alloc = reg_ops->pktmbuf_alloc;
    g_udk_reg_ops.pktmbuf_alloc_bulk = reg_ops->pktmbuf_alloc_bulk;
    g_udk_reg_ops.pktmbuf_free = reg_ops->pktmbuf_free;
    g_udk_reg_ops.pktmbuf_pool_create = reg_ops->pktmbuf_pool_create;

    g_udk_reg_ops.mheap_alloc = reg_ops->mheap_alloc;
    g_udk_reg_ops.mheap_free = reg_ops->mheap_free;

    return 0;
}
